package com.atom.module.lib.opengles.shader

import android.opengl.GLES30
import com.atom.module.lib.opengles.util.ShaderUtils

/**
 * A simple helper class for holding handles to program variables.
 */
class GlProgramLocation private constructor(
    program: Int,
    type: Type,
    val name: String
) {

    private enum class Type { ATTRIB, UNIFORM }

    val value: Int = when (type) {
        Type.ATTRIB -> GLES30.glGetAttribLocation(program, name)
        Type.UNIFORM -> GLES30.glGetUniformLocation(program, name)
    }

    init {
        ShaderUtils.checkGlProgramLocation(value, name)
    }

    companion object {
        fun getAttrib(program: Int, name: String): GlProgramLocation =
            GlProgramLocation(program, Type.ATTRIB, name)

        fun getUniform(program: Int, name: String): GlProgramLocation =
            GlProgramLocation(program, Type.UNIFORM, name)
    }
}